package com.guomei.service.pay;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Component
@Slf4j
public class PaymentStrategy {
    private final Map<String, PaymentService> paymentServices = new HashMap<>();

    @Resource
    private AlipayService alipayService;

    @Resource
    private WechatPayService wechatPayService;

    @PostConstruct
    public void init() {
        paymentServices.put("alipay", alipayService);
        paymentServices.put("wechat", wechatPayService);
    }

    /**
     * 根据支付类型获取对应的支付服务
     */
    public PaymentService getPaymentService(String payType) {
        PaymentService service = paymentServices.get(payType);
        if (service == null) {
            log.info("未找到对应的支付服务：{}", payType);
        }
        return service;
    }
}
